home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++,comp.edu
- Subject: Re: ANSI C and POSIX (was Re: C/C++ knocks the crap out of Ada)
- Date: 8 Apr 1996 07:59:20 -0500
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4kb2j8$an0@solutions.solon.com>
- References: <JSA.96Feb16135027@organon.com> <dewar.828879781@schonberg> <4k9qhe$65r@solutions.solon.com> <dewar.828936837@schonberg>
- Reply-To: seebs@solon.com
- NNTP-Posting-Host: solutions.solon.com
-
- In article <dewar.828936837@schonberg>, Robert Dewar <dewar@cs.nyu.edu> wrote:
- >Peter said
- >"Now, as it happens, Linux does do the right thing - if I define my own
- >read(), I get *my* read any time I call read, so the implementation is
- >conforming."
- >Boy, this sure has wandered!
-
- True enough. The above is the only ANSI related issue.
-
- >THe original issue was the semantic behavior
- >of read. Unlike other unices, in Linux, the bounds check for the read
- >buffer is based on the requested count, rather than the actual count
- >of data bytes read. It is hard to say either approach is right or
- >wrong, but they are different enough to cause portability problems.
-
- How? No offense meant, but any code which can be affected by this is flat
- out broken. POSIX-style read is to be given a pointer to at least nbytes
- of space, for the information read. Period.
-
- No correct code can ever be affected by the behavior of read when nbytes
- is larger than the size of the buffer. (For latecomers, the question is
- what happens if you *KNOW* that the file only has, say 100 bytes left, so
- call read with a 100-byte buffer, and nbytes==256.)
-
- I can't see how this is a "portability problem" any more than it's a
- portability problem that some systems will crash on
- printf("%s", (char *) 0);
- ... (SunOS won't, though.) Something which works only on some systems is
- not a portability problem *if there is no standard saying it works*. Likewise
- i = ++i;
- producing different results on different machines is not a "portability
- problem".
-
- If read() behaved dramatically differently with valid inputs, I would see it
- as a portability problem.
-
- (This applies to most of the C standard library, as well, of course. The
- behavior you're used to, such as "void main(void)" or "fflush(stdin)" not
- working, is not a portability problem, it's broken code.)
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-